package strategy1.pay;

import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ReflectUtil;
import org.springframework.stereotype.Component;

/**
 * @author ycd0075
 * @date 2023-04-27 17:51
 */
@Component
public class PaymentFactory {

    public static IPayment getPayStrategy(String type) {
        // 1.通过枚举中的type获取对应的value
        PayStrategyEnum value = EnumUtil.likeValueOf(PayStrategyEnum.class, type);
        // 2.使用反射机制创建对应的策略类
        IPayment payment = ReflectUtil.newInstance(value.getValue());
        return payment;
    }

}
